package com.nacos.example.consumer.controller;

import com.nacos.example.consumer.server.ProviderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RequestMapping("/api/consumer")
@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProviderFeignService providerFeignService;

    @RequestMapping(value = "/echo1", method = RequestMethod.GET)
    public String echo1() {
        System.out.println("===========这是用restTemplate方式调用服务，带负载均衡。");
        return restTemplate.getForObject("http://service-provider/api/provider/echo", String.class);
    }

    @RequestMapping(value = "/echo2", method = RequestMethod.GET)
    public String echo2() {
        System.out.println("===========这是用FeignClient方式调用服务，带负载均衡。");
        return providerFeignService.echo();
    }

}
